/******************************************************************************
 * (C) Copyright 2020 Atech-Automotive
 * FILE NAME:    app_sci1_Itf.c
 * DESCRIPTION:
 * 
 * DATE BEGUN:   2020/09/18
 * BY:           yong.ding
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */

/*****************************************************************************
** #include 
*****************************************************************************/
#include <string.h>
#include "app_sci1_Itf.h"
#include "drv_SCI.h"
#include  "msg_sciApi.h"
#include  "msg_canApi.h"
#include "hwa_outputs.h"
#include "hwa_inputs.h"
#include "drv_can.h"
#pragma CODE_SEG  OTHER_ROM

/*****************************************************************************
** function prototypes
*****************************************************************************/
#if	CAN_RX_USE_TEST
static void sci1ItfGetmessageFromCanMsg123(BOOL sended_flg);
static void sci1ItfGetmessageFromCanMsg124(BOOL sended_flg);
#endif

#if	CAN_RX_USE_X70
static void sci1ItfGetmessageFromCanMsg392(BOOL sended_flg);
static void sci1ItfGetmessageFromCanMsg517(BOOL sended_flg);
static void sci1ItfGetmessageFromCanMsg2C0(BOOL sended_flg);
static void sci1ItfGetmessageFromCanMsg340(BOOL sended_flg);
#endif
static void app_sci1ItfWriteWFeedbackFlag(UINT8 id,UINT8 sub_id,BOOL set);

/****************************************************************************/
BOOL app_sci1ItfGetIGN(void)
{
    return HWA_GetInput(SI_PP0_IN);
}


BOOL app_sci1ItfSendFrame(UINT8 id,BOOL sub_exist,UINT8 sub_id,UINT8 txData_len,UINT8* p_u8_txData)
{
	return drv_sci1SendFrame(id,sub_exist,sub_id,txData_len,p_u8_txData);
}

BOOL app_sci1ItfGetMessage(UINT8 *u8_id,UINT8 *u8_sub_id, UINT8 *u8_length, UINT8 *p_u8_txData)
{
    return drv_sci1_v_getMessage(u8_id,u8_sub_id,u8_length,p_u8_txData);
}

UINT8 app_sci1ItfGetRxMessageCount(void)
{
    return drv_sci1_u8_getRxMessageCount();  
}

/******************************************************************************/
/**
 * Function Name: app_sci1CheckTimeout
 * Description: none
 *
 * Param:	none
 * Return:	none
 * _____________________________________________________________________________
 *	   Date 			Changes Description 			   Author
 *	09/13/2020				        					yong.ding
 ******************************************************************************/

static void app_sci1ItfWriteWFeedbackFlag(UINT8 id,UINT8 sub_id,BOOL set)
{
	SCI_RX_MSG_S **ptr;
	SCI_RX_LONG_MSG_S **ptr2;
	ptr = p_s_sci1RxTable;
	while((*ptr)->Id != 0)
    {   
        if((*ptr)->SendType == SCI_EVENT &&((*ptr)->Id==id)&&((*ptr)->Sub_Id==sub_id))
        {
            (*ptr)->Waite_Feedback_Flag = set;
			return ;
        }
        ptr++;
    }

	ptr2 = p_s_sci1LongRxTable;
	while((*ptr2)->Id != 0)
    {   
        if((*ptr2)->SendType == SCI_EVENT &&((*ptr2)->Id==id)&&((*ptr2)->Sub_Id==sub_id))
        {
            (*ptr2)->Waite_Feedback_Flag = set;
			return ;
        }
        ptr2++;
    }
}


void app_sci1ItfEventSent(SCI_TX_MSG_S *ptr)
{

	if((ptr)->SendType == SCI_EVENT)
	{
		if((ptr)->Trigger)
		{
			/*send msg*/
			if (app_sci1ItfSendFrame((ptr)->Id,(ptr)->Sub_Id_exist,(ptr)->Sub_Id,(ptr)->Length,(ptr)->Data) == FALSE)
			{

			}
			else
			{
				/* transmit success */
				(ptr)->Trigger = FALSE;
				app_sci1ItfWriteWFeedbackFlag((ptr)->Id,(ptr)->Sub_Id,TRUE);//set Waite_Feedback_Flag
				if((ptr)->NobackRetry_cn >= (ptr)->NobackRetry_cn_max)
				{
					app_sci1ItfWriteWFeedbackFlag((ptr)->Id,(ptr)->Sub_Id,FALSE);//clear set Waite_Feedback_Flag
					(ptr)->NobackRetry_cn = 0;
					(ptr)->NobackTimer = 0;
				}

			} 
		}
	}
}

void app_sci1ItfUpdataTxMsgs(void)
{ 

	static BOOL cpu_ready=FALSE;
	static BOOL sci1_event_msg_firstSend_flag = FALSE;
	static UINT16 cpu_ready_time_out = 0;


//ru guo cpu mei qi dong hao ,bing qie chao shi le ,ze MCU kai shi fa chuan kou bao wen.
	if(cpu_ready_time_out < 800)//8s
	{
		cpu_ready_time_out++;
		if(cpu_ready_time_out%50 == 0)
		{
			SciMsg0E_02_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0E_02_Tx);
			if(s_u8_rd(&SciMsg0E_02_Rx, 0,8) == 1)
			{
				cpu_ready = TRUE;
			}
		}
	}
	else
	{
		cpu_ready = TRUE;
	}
#if	CAN_RX_USE_TEST

	if(cpu_ready == TRUE)
	{
		sci1ItfGetmessageFromCanMsg123(sci1_event_msg_firstSend_flag);
		sci1ItfGetmessageFromCanMsg124(sci1_event_msg_firstSend_flag);

		sci1_event_msg_firstSend_flag = TRUE;//bao zheng cpu ready zhi hou fa yi ci shi jian bao wen
	}
#endif

#if	CAN_RX_USE_X70

	if(cpu_ready == TRUE)
	{
		sci1ItfGetmessageFromCanMsg392(sci1_event_msg_firstSend_flag);
		sci1ItfGetmessageFromCanMsg517(sci1_event_msg_firstSend_flag);
		sci1ItfGetmessageFromCanMsg2C0(sci1_event_msg_firstSend_flag);
		sci1ItfGetmessageFromCanMsg340(sci1_event_msg_firstSend_flag);
		sci1_event_msg_firstSend_flag = TRUE;//bao zheng cpu ready zhi hou fa yi ci shi jian bao wen
	}
#endif

	
}
#if	CAN_RX_USE_TEST
/***********************************************************
	chuan kou buf Get message From CanMsg123 buf,ru guo sci shi shi jian bao wen ,ze dang shi jiu fa song gei CPU.
**********************************************************/
static void sci1ItfGetmessageFromCanMsg123(BOOL sended_flg)
{
	UINT8 u8_temp=0; 
	UINT16 u16_temp=0;
	SINT16 s16_temp = 0;
	UINT8 u8_last=0; 
	UINT16 u16_last=0;

	static UINT16 u16_event_cycle_t = 0;

	if(u16_event_cycle_t < 50)
	{ 
		u16_event_cycle_t++;
	}
	else
	{
		u16_event_cycle_t = 0;
	}
	//////////////////////////CanMsg123_Rx chu li////////////////////////////////////////////////
	u8_last = c_u8_LastData_rd(&CanMsg123_Rx,0,2);//KeySts
	u8_temp = c_u8_rd(&CanMsg123_Rx,0,2);//KeySts
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_u8_LastData_wr(&CanMsg123_Rx,0,2,u8_temp);
		if(u8_temp == 0)
		{
//			s_u8_wr(&SciMsg1C_Tx, 0,1,u8_temp);//biao shi xi tong dian yuan guan bi
//			SciMsg1C_Tx.Trigger = TRUE;
//			app_sci1ItfEventSent(&SciMsg1C_Tx);//sci The order was issued at that moment if is event order
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg1C_Tx, 0,1,1);//biao shi xi tong dian yuan da kai
			SciMsg1C_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg1C_Tx);//sci The order was issued at that moment if is event order
		}
		else
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,12);//qi che da huo
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);//sci The order was issued at that moment if is event order
		}
	}

	u8_last = c_bool_LastData_rd(&CanMsg123_Rx,2,1);//RHTurnlightSts
	u8_temp = c_bool_rd(&CanMsg123_Rx,2,1);//RHTurnlightSts
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg123_Rx,2,1,u8_temp);
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,5);//you zhuan xiang deng guan
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,4);//you zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}	
	else if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	{
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,5);//you zhuan xiang deng guan
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,4);//you zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}

	}

	u8_last = c_bool_LastData_rd(&CanMsg123_Rx,3,1);// LHTurnlightSts
	u8_temp = c_bool_rd(&CanMsg123_Rx,3,1);// LHTurnlightSts
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg123_Rx,3,1,u8_temp);
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,3);//zuo zhuan xiang deng guan
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,2);//zuo zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}
	else if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	{
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,3);//zuo zhuan xiang deng guan
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,2);//zuo zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}

	}


	u8_last = c_bool_LastData_rd(&CanMsg123_Rx,4,1);//ReverseGearSwitch
	u8_temp = c_bool_rd(&CanMsg123_Rx,4,1);//ReverseGearSwitch
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg123_Rx,4,1,u8_temp);
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,1);//tui chu dao che zhuang tai 
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,0);//jin ru dao che zhuang tai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}
	else if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	{
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,1);//tui chu dao che zhuang tai 
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,0);//jin ru dao che zhuang tai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}

///////////////zhou qi chuan kou bao wen bu yong shi shi fa song ////////////		
	u8_temp = c_bool_rd(&CanMsg123_Rx,18,1);//VehicleSpeedVSOSigValidData
	if(u8_temp == 0)//che su you xiao
	{
		u16_temp = c_u16_rd(&CanMsg123_Rx,19,13);//VehicleSpeed VSOSig
		u16_temp = u16_temp/16;
		s_u16_wr(&SciMsg02_Tx, 0,16,u16_temp);		//zhou qi bao wen bu yong li ma fa song .
	}


	u16_temp = c_u16_rd(&CanMsg123_Rx,34,16);//SteeringAngle
	s16_temp = u16_temp/16 - 2048;
	s_u16_wr(&SciMsg01_Tx, 8,8,s16_temp*10);


}

static void sci1ItfGetmessageFromCanMsg124(BOOL sended_flg)
{
	UINT8 u8_temp=0; 
	UINT16 u16_temp=0;
	SINT16 s16_temp = 0;
	UINT8 u8_last=0; 
	UINT16 u16_last=0;

	u8_last = c_bool_LastData_rd(&CanMsg124_Rx,1,1);//CalibrationRequest
	u8_temp = c_bool_rd(&CanMsg124_Rx,1,1);//CalibrationRequest
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg124_Rx,1,1,u8_temp);
		if(u8_temp == 1)		//jin ru biao ding
		{
			s_u8_wr(&SciMsg0B_Tx, 0,8,1);//jin ru biao ding
			SciMsg0B_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0B_Tx);

		}
	}

	u8_last = c_bool_LastData_rd(&CanMsg124_Rx,2,1);//LDWSwitch
	u8_temp = c_bool_rd(&CanMsg124_Rx,2,1);//LDWSwitch
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg124_Rx,2,1,u8_temp);
		if(u8_temp == 0)		//LDWSwitch ON
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,1);//KAI QI
			s_u8_wr(&SciMsg09_Tx, 8,8,2);//dao lu pian li yu jing
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
		else			//LDWSwitch OFF
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,0);//guan bi
			s_u8_wr(&SciMsg09_Tx, 8,8,2);//dao lu pian li yu jing
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
	}

	u8_last = c_bool_LastData_rd(&CanMsg124_Rx,3,1);//BSDSwitch
	u8_temp = c_bool_rd(&CanMsg124_Rx,3,1);//BSDSwitch
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg124_Rx,3,1,u8_temp);
		if(u8_temp == 0)		//BSDSwitch ON
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,1);//KAI QI
			s_u8_wr(&SciMsg09_Tx, 8,8,1);//MANG QU JIAN CE
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
		else			//LDWSwitch OFF
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,0);//guan bi
			s_u8_wr(&SciMsg09_Tx, 8,8,1);//mang qu jian ce
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
	}

	u8_last = c_u8_LastData_rd(&CanMsg124_Rx,8,2);//AVM_OP_VIEW_DVR_SW
	u8_temp = c_u8_rd(&CanMsg124_Rx,8,2);//AVM_OP_VIEW_DVR_SW
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_u8_LastData_wr(&CanMsg124_Rx,8,2,u8_temp);
		if(u8_temp == 1)		//open avm
		{
//			s_u8_wr(&SciMsg0B_Tx, 0,8,0);//qie huan zhu jie mian
//			SciMsg0B_Tx.Trigger = TRUE;
//			app_sci1ItfEventSent(&SciMsg0B_Tx);
		}
		else if(u8_temp == 2)			//open dvr
		{
			s_u8_wr(&SciMsg0D_Tx, 0,8,1);//open dvr
			SciMsg0D_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0D_Tx);
		}
		else if(u8_temp == 0)//close dvr
		{
			s_u8_wr(&SciMsg0D_Tx, 0,8,0);//close dvr
			SciMsg0D_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0D_Tx);
		}
	}		
	u8_last = c_u8_LastData_rd(&CanMsg124_Rx,10,3);//AVM_SET_LANG
	u8_temp = c_u8_rd(&CanMsg124_Rx,10,3);//AVM_SET_LANG
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_u8_LastData_wr(&CanMsg124_Rx,10,3,u8_temp);
		if(u8_temp == 0)		//chinese
		{
			s_u8_wr(&SciMsg06_Tx, 0,8,0);//jian ti zhong wen

			SciMsg06_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg06_Tx);
		}
		else if(u8_temp == 1)			//english
		{
			s_u8_wr(&SciMsg06_Tx, 0,8,2);//english
			SciMsg06_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg06_Tx);
		}
	}

//	u8_last = c_u8_LastData_rd(&CanMsg124_Rx,13,2);//AVM_DATE_TP_Sts
	u8_temp = c_u8_rd(&CanMsg124_Rx,13,2);//AVM_DATE_TP_Sts
	if(u8_temp == 1)//fa shi jian
	{
		if(memcmp(&(CanMsg124_Rx.Data[2]),&(CanMsg124_Rx.LastData[2]),6) != 0)
		{
			memcpy(&(CanMsg124_Rx.LastData[2]),&(CanMsg124_Rx.Data[2]),6);
			u8_temp = c_u8_rd(&CanMsg124_Rx,16,8);//year
			s_u8_wr(&SciMsg05_Tx, 0,8,u8_temp);//year
			u8_temp = c_u8_rd(&CanMsg124_Rx,24,8);//month
			s_u8_wr(&SciMsg05_Tx, 8,8,u8_temp);//month
			u8_temp = c_u8_rd(&CanMsg124_Rx,32,8);//date
			s_u8_wr(&SciMsg05_Tx, 16,8,u8_temp);//date
			u8_temp = c_u8_rd(&CanMsg124_Rx,40,8);//hour
			s_u8_wr(&SciMsg05_Tx, 24,8,u8_temp);//hour
			u8_temp = c_u8_rd(&CanMsg124_Rx,48,8);//minute
			s_u8_wr(&SciMsg05_Tx, 32,8,u8_temp);//minute
			u8_temp = c_u8_rd(&CanMsg124_Rx,56,8);//second
			s_u8_wr(&SciMsg05_Tx, 40,8,u8_temp);//second
			SciMsg05_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg05_Tx);
		}

	}
	else if(u8_temp == 2)//fa zuo biao
	{
		if(memcmp(&(CanMsg124_Rx.Data[2]),&(CanMsg124_Rx.LastData[2]),6) != 0)
		{
			memcpy(&(CanMsg124_Rx.LastData[2]),&(CanMsg124_Rx.Data[2]),6);
			u8_temp = c_u8_rd(&CanMsg124_Rx,16,2);//an xia or tan qi
			if(u8_temp == 1) s_u8_wr(&SciMsg04_Tx, 0,8,1);////an xia
			if(u8_temp == 2) s_u8_wr(&SciMsg04_Tx, 0,8,2);//tan qi
			u16_temp = c_u16_rd(&CanMsg124_Rx,32,16);//x zuo bio
			s_u16_wr(&SciMsg04_Tx, 16,16,u16_temp);//x zuo bio
			u16_temp = c_u16_rd(&CanMsg124_Rx,48,16);//y zuo bio
			s_u16_wr(&SciMsg04_Tx, 32,16,u16_temp);//y zuo bio
			SciMsg04_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg04_Tx);
		}

	}
	
}
#endif
#if	CAN_RX_USE_X70
static void sci1ItfGetmessageFromCanMsg392(BOOL sended_flg)
{
	UINT8 u8_temp=0; 
	UINT16 u16_temp=0;
	SINT16 s16_temp = 0;
	UINT8 u8_last=0; 
	UINT16 u16_last=0;
	static UINT16 u16_event_cycle_t = 0;
	static UINT16 u16_LLight_off_t = 0;
	static UINT16 u16_RLight_off_t = 0;
	if(u16_event_cycle_t < 10)
	{
		u16_event_cycle_t++;
	}
	else
	{
		u16_event_cycle_t = 0;
	}
	
	u8_last = c_u8_LastData_rd(&CanMsg392_Rx,5,2);//KeySts
	u8_temp = c_u8_rd(&CanMsg392_Rx,5,2);//KeySts
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_u8_LastData_wr(&CanMsg392_Rx,5,2,u8_temp);
		if(u8_temp == 0)
		{
//			s_u8_wr(&SciMsg1C_Tx, 0,1,u8_temp);//biao shi xi tong dian yuan guan bi
//			SciMsg1C_Tx.Trigger = TRUE;
//			app_sci1ItfEventSent(&SciMsg1C_Tx);//sci The order was issued at that moment if is event order
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg1C_Tx, 0,1,1);//biao shi xi tong dian yuan da kai
			SciMsg1C_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg1C_Tx);//sci The order was issued at that moment if is event order
		}
		else
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,12);//qi che da huo
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);//sci The order was issued at that moment if is event order
		}
	}
	u8_last = c_bool_LastData_rd(&CanMsg392_Rx,8,1);//RHTurnlightSts
	u8_temp = c_bool_rd(&CanMsg392_Rx,8,1);//RHTurnlightSts
#if 0
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg392_Rx,8,1,u8_temp);
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,5);//you zhuan xiang deng guan
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,4);//you zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}	
#endif
//	else if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	{
		if(u8_temp == 0)
		{
			if(u16_RLight_off_t < 8)//u16_event_cycle_t == 0 biao shi 100ms le, 8*100ms
			{	
				u16_RLight_off_t++;
			}
			else
			{
				s_u8_wr(&SciMsg08_Tx, 0,8,5);//you zhuan xiang deng guan
				SciMsg08_Tx.Trigger = TRUE;
				app_sci1ItfEventSent(&SciMsg08_Tx);
			}
		}
		else if(u8_temp == 1)
		{
			u16_RLight_off_t = 0;
			s_u8_wr(&SciMsg08_Tx, 0,8,4);//you zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}

	}

	u8_last = c_bool_LastData_rd(&CanMsg392_Rx,9,1);// LHTurnlightSts
	u8_temp = c_bool_rd(&CanMsg392_Rx,9,1);// LHTurnlightSts
#if 0
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg392_Rx,9,1,u8_temp);
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,3);//zuo zhuan xiang deng guan
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,2);//zuo zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}
#endif
//	else if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	{
		if(u8_temp == 0)
		{
			if(u16_LLight_off_t < 8)//u16_event_cycle_t == 0 biao shi 100ms le, 8*100ms
			{	
				u16_LLight_off_t++;
			}
			else
			{
				s_u8_wr(&SciMsg08_Tx, 0,8,3);//zuo zhuan xiang deng guan
				SciMsg08_Tx.Trigger = TRUE;
				app_sci1ItfEventSent(&SciMsg08_Tx);
			}
		}
		else if(u8_temp == 1)
		{
			u16_LLight_off_t = 0;
			s_u8_wr(&SciMsg08_Tx, 0,8,2);//zuo zhuan xiang deng kai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}

	}


	u8_last = c_bool_LastData_rd(&CanMsg392_Rx,35,1);//ReverseGearSwitch
	u8_temp = c_bool_rd(&CanMsg392_Rx,35,1);//ReverseGearSwitch
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg392_Rx,35,1,u8_temp);
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,1);//tui chu dao che zhuang tai 
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,0);//jin ru dao che zhuang tai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}
	else if(u8_temp == u8_last && (u16_event_cycle_t == 0))//te shu de shi jian zheng : shi jian chan sheng hou ,zhou qi fa song gai shi jian dui ying de nei rong.
	{
		if(u8_temp == 0)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,1);//tui chu dao che zhuang tai 
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
		else if(u8_temp == 1)
		{
			s_u8_wr(&SciMsg08_Tx, 0,8,0);//jin ru dao che zhuang tai
			SciMsg08_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg08_Tx);
		}
	}

}
static void sci1ItfGetmessageFromCanMsg517(BOOL sended_flg)
{
	UINT8 u8_temp=0; 
	UINT16 u16_temp=0;
	SINT16 s16_temp = 0;
	UINT8 u8_last=0; 
	UINT16 u16_last=0;
	UINT8 checksum = 0;
	static UINT16 u16_avm_button_open_t = 0;
	static UINT16 u16_dvr_button_open_t = 0;
	static UINT16 u16_close_button_t = 0;
	u8_last = c_bool_LastData_rd(&CanMsg517_Rx,1,1);//CalibrationRequest
	u8_temp = c_bool_rd(&CanMsg517_Rx,1,1);//CalibrationRequest
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg517_Rx,1,1,u8_temp);
		if(u8_temp == 1)		//jin ru biao ding
		{
			s_u8_wr(&SciMsg0B_Tx, 0,8,1);//jin ru biao ding
			SciMsg0B_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0B_Tx);

		}
	}

	u8_last = c_bool_LastData_rd(&CanMsg517_Rx,2,1);//LDWSwitch
	u8_temp = c_bool_rd(&CanMsg517_Rx,2,1);//LDWSwitch
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg517_Rx,2,1,u8_temp);
		if(u8_temp == 0)		//LDWSwitch ON
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,1);//KAI QI
			s_u8_wr(&SciMsg09_Tx, 8,8,2);//dao lu pian li yu jing
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
		else			//LDWSwitch OFF
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,0);//guan bi
			s_u8_wr(&SciMsg09_Tx, 8,8,2);//dao lu pian li yu jing
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
	}

	u8_last = c_bool_LastData_rd(&CanMsg517_Rx,3,1);//BSDSwitch
	u8_temp = c_bool_rd(&CanMsg517_Rx,3,1);//BSDSwitch
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_bool_LastData_wr(&CanMsg517_Rx,3,1,u8_temp);
		if(u8_temp == 0)		//BSDSwitch ON
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,1);//KAI QI
			s_u8_wr(&SciMsg09_Tx, 8,8,1);//MANG QU JIAN CE
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
		else			//LDWSwitch OFF
		{
			s_u8_wr(&SciMsg09_Tx, 0,8,0);//guan bi
			s_u8_wr(&SciMsg09_Tx, 8,8,1);//mang qu jian ce
			SciMsg09_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg09_Tx);
		}
	}

	u8_last = c_u8_LastData_rd(&CanMsg517_Rx,8,2);//AVM_OP_VIEW_DVR_SW
	u8_temp = c_u8_rd(&CanMsg517_Rx,8,2);//AVM_OP_VIEW_DVR_SW
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_u8_LastData_wr(&CanMsg517_Rx,8,2,u8_temp);
		if(u8_temp == 1)		//open avm
		{
//			s_u8_wr(&SciMsg0B_Tx, 0,8,0);//qie huan zhu jie mian
//			SciMsg0B_Tx.Trigger = TRUE;
//			app_sci1ItfEventSent(&SciMsg0B_Tx);
			//update 0x520
			c_u8_wr(&CanMsg520_Tx,8,2,1);
			//fa song 0x520
			drv_can_e_sendFrame(0X520, 0, 8, CanMsg520_Tx.Data);
		}
		else if(u8_temp == 2)			//open dvr
		{
			s_u8_wr(&SciMsg0D_Tx, 0,8,1);//open dvr
			SciMsg0D_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0D_Tx);
			c_u8_wr(&CanMsg520_Tx,8,2,2);
			//fa song 0x520
			drv_can_e_sendFrame(0X520, 0, 8, CanMsg520_Tx.Data);

		}
		else if(u8_temp == 0)//close dvr
		{
			s_u8_wr(&SciMsg0D_Tx, 0,8,0);//close dvr
			SciMsg0D_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg0D_Tx);
			c_u8_wr(&CanMsg520_Tx,8,2,0);
			//fa song 0x520
			drv_can_e_sendFrame(0X520, 0, 8, CanMsg520_Tx.Data);

		}
	}	
	else
	{
		if(u8_temp == 3)
		{
			c_u8_wr(&CanMsg520_Tx,8,2,3);
			//fa song 0x520
			//drv_can_e_sendFrame(0X520, 0, 8, CanMsg520_Tx.Data);
		}
	}
# if 0
	else if(u8_temp == u8_last)
	{
		if(u8_temp == 1)
		{
			if(u16_avm_button_open_t < 10)
			{
				u16_avm_button_open_t++;
			}
			else
			{
				//update 0x520
				drv_can_e_sendFrame(UINT32 u32_id, UINT8 u8_prio, UINT8 u8_length, UINT8 *p_u8_txData)//fa 0x520  tong zhi RRM avm yi jing da kai
			}
		}
		else if(u8_temp == 2)			//open dvr
		{
			
			if(u16_dvr_button_open_t < 10)
			{
				u16_dvr_button_open_t++;
			}
			else
			{
				s_u8_wr(&SciMsg0D_Tx, 0,8,1);//open dvr
				SciMsg0D_Tx.Trigger = TRUE;
				app_sci1ItfEventSent(&SciMsg0D_Tx);
			}
		}
		else if(u8_temp == 0)//close dvr
		{
			if(u16_close_button_t < 10)
			{
				u16_close_button_t++;
			}
			else
			{
				s_u8_wr(&SciMsg0D_Tx, 0,8,0);//close dvr
				SciMsg0D_Tx.Trigger = TRUE;
				app_sci1ItfEventSent(&SciMsg0D_Tx);
			}
		}
		else
		{
			u16_avm_button_open_t = 0;
			u16_dvr_button_open_t = 0;
			u16_close_button_t = 0;
			////fa 0x520  AVM_OP_VIEW_DVR_SW_Sta tian 3
		}
	}
#endif
	u8_last = c_u8_LastData_rd(&CanMsg517_Rx,10,3);//AVM_SET_LANG
	u8_temp = c_u8_rd(&CanMsg517_Rx,10,3);//AVM_SET_LANG
	if(u8_temp != u8_last || (sended_flg==FALSE))
	{
		c_u8_LastData_wr(&CanMsg517_Rx,10,3,u8_temp);
		if(u8_temp == 0)		//chinese
		{
			s_u8_wr(&SciMsg06_Tx, 0,8,0);//jian ti zhong wen

			SciMsg06_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg06_Tx);
		}
		else if(u8_temp == 1)			//english
		{
			s_u8_wr(&SciMsg06_Tx, 0,8,2);//english
			SciMsg06_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg06_Tx);
		}
	}

//	u8_last = c_u8_LastData_rd(&CanMsg517_Rx,13,2);//AVM_DATE_TP_Sts
	u8_temp = c_u8_rd(&CanMsg517_Rx,13,2);//AVM_DATE_TP_Sts
	if(u8_temp == 1)//fa shi jian
	{
		if(memcmp(&(CanMsg517_Rx.Data[2]),&(CanMsg517_Rx.LastData[2]),6) != 0)
		{
			memcpy(&(CanMsg517_Rx.LastData[2]),&(CanMsg517_Rx.Data[2]),6);
			u8_temp = c_u8_rd(&CanMsg517_Rx,16,8);//year
			s_u8_wr(&SciMsg05_Tx, 0,8,u8_temp);//year
			u8_temp = c_u8_rd(&CanMsg517_Rx,24,8);//month
			s_u8_wr(&SciMsg05_Tx, 8,8,u8_temp);//month
			u8_temp = c_u8_rd(&CanMsg517_Rx,32,8);//date
			s_u8_wr(&SciMsg05_Tx, 16,8,u8_temp);//date
			u8_temp = c_u8_rd(&CanMsg517_Rx,40,8);//hour
			s_u8_wr(&SciMsg05_Tx, 24,8,u8_temp);//hour
			u8_temp = c_u8_rd(&CanMsg517_Rx,48,8);//minute
			s_u8_wr(&SciMsg05_Tx, 32,8,u8_temp);//minute
			u8_temp = c_u8_rd(&CanMsg517_Rx,56,8);//second
			s_u8_wr(&SciMsg05_Tx, 40,8,u8_temp);//second
			SciMsg05_Tx.Trigger = TRUE;
			app_sci1ItfEventSent(&SciMsg05_Tx);
		}

	}
	else if(u8_temp == 2)//fa zuo biao
	{
		if(memcmp(&(CanMsg517_Rx.Data[2]),&(CanMsg517_Rx.LastData[2]),6) != 0)
		{
			checksum = CanMsg517_Rx.Data[2] + CanMsg517_Rx.Data[3] + CanMsg517_Rx.Data[4] + CanMsg517_Rx.Data[5] + CanMsg517_Rx.Data[6];
			if((checksum^0xff) == CanMsg517_Rx.Data[7])
			{
				memcpy(&(CanMsg517_Rx.LastData[2]),&(CanMsg517_Rx.Data[2]),6);
				u8_temp = c_u8_rd(&CanMsg517_Rx,16,2);//an xia or tan qi
				if(u8_temp == 1) s_u8_wr(&SciMsg04_Tx, 0,8,1);////an xia
//				if(u8_temp == 1) s_u8_wr(&SciMsg04_Tx, 0,8,0);////an xia bing tan qi
				if(u8_temp == 2 || (u8_temp == 3)) s_u8_wr(&SciMsg04_Tx, 0,8,2);//tan qi
				u16_temp = c_u16_rd(&CanMsg517_Rx,32,16);//x zuo biao
				u16_temp = (UINT16)(((UINT32)u16_temp * 1000)/1264);
				s_u16_wr(&SciMsg04_Tx, 16,16,u16_temp);//x zuo biao
				u16_temp = c_u16_rd(&CanMsg517_Rx,48,16);//y zuo biao
				u16_temp = (UINT16)(((UINT32)u16_temp * 1000)/714);
				s_u16_wr(&SciMsg04_Tx, 32,16,u16_temp);//y zuo biao
				SciMsg04_Tx.Trigger = TRUE;
				app_sci1ItfEventSent(&SciMsg04_Tx);
			}
		}

	}

}
static void sci1ItfGetmessageFromCanMsg2C0(BOOL sended_flg)
{
	UINT8 u8_temp=0; 
	UINT16 u16_temp=0;
	SINT16 s16_temp = 0;
	UINT8 u8_last=0; 
	UINT16 u16_last=0;
	u8_temp = c_bool_rd(&CanMsg2C0_Rx,31,1);//VehicleSpeedVSOSigValidData
	if(u8_temp == 0)//che su you xiao
	{
		u16_temp = c_u16_rd(&CanMsg2C0_Rx,16,13);//VehicleSpeed VSOSig
		u16_temp = u16_temp/16;
		s_u16_wr(&SciMsg02_Tx, 0,16,u16_temp);		//zhou qi bao wen bu yong li ma fa song .
	}

}
static void sci1ItfGetmessageFromCanMsg340(BOOL sended_flg)
{
	UINT8 u8_temp=0; 
	UINT16 u16_temp=0;
	SINT16 s16_temp = 0;
	UINT8 u8_last=0; 
	UINT16 u16_last=0;
	u16_temp = c_u16_rd(&CanMsg340_Rx,34,16);//SteeringAngle
	s16_temp = u16_temp/16 - 2048;
	s_u16_wr(&SciMsg01_Tx, 8,8,s16_temp*10);
}
#endif
/*for other interface*/

#pragma CODE_SEG  DEFAULT
/*****************************************************************************
** End File
*****************************************************************************/
